#include "scene.h"
#include <math.h>
#include <QtGlobal>
#include <QtCore/qmath.h>

bool Scene::MoureEnemicsRandom()
{
    const int length = m_rows * m_columns;
    QVector<cell_state_t> tmp(length, empty);
    int from, r, c, hr, hc, fr, fc, angle, id;
    bool gameover = false;
    HeroLocation(hr, hc);
    from = 0;
    for(int i = 0; i < length; ++i) tmp[i] = m_tauler.at(i);
    for(int i = 0; !gameover && i < m_NumBaddies; ++i)
    {
        int e = EnemyLocation(from, tmp, id);
	if(id < 0) break;
        r = e / m_columns;
        c = e % m_columns;
        angle = enemiesOrtientation.at(id);
        fr = r;
        fc = c;
        switch(qrand() % 15)
        {
        case 0:
                        enemiesOrtientation[id] = (angle + 90) % 360; break;
        case 1:
                        enemiesOrtientation[id] = (angle + 270) % 360; break;
        default:
                        AdvanceCharacter(1, fr, fc, angle, (cell_state_t)(enemy0 + id));
                        if((fr == r) && (fc == c))
                        {
                                if(qrand() % 2) enemiesOrtientation[id] = (angle + 90) % 360;
                                else enemiesOrtientation[id] = (angle + 270) % 360;
                        }
        }
        gameover = (fr == hr && fc == hc);
        from = e + 1;
    }

    return gameover;

}
